package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.mapper.OrdersMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: OrdersController
 * USER: zhang
 * DATE: 2023/5/28
 * DESCRIPTION :C端-订单信息表现层接口
 */
@Slf4j
@RestController
@Api(tags = "C端-订单信息表现层")
@RequestMapping("user/order")
public class OrdersController {
    @Resource
    private OrdersService ordersService;

    /**
     * 用户下单功能
     *
     * @param ordersSubmitDTO 订单基本信息
     * @return 全局通用返回信息Bean(订单id + 订单号 + 订单金额 + 下单时间)
     */
    @ApiOperation("C端-用户提交订单功能")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = ordersService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    /**
     * 用户请求支付功能
     *
     * @param ordersPaymentDTO 用于请求支付相关信息(订单号码/付款方式)
     * @return 全局通用返回信息Bean(微信支付基础信息VO)
     */
    @ApiOperation("C端-用户请求支付功能")
    @PutMapping("/payment")
    public Result<OrderPaymentVO> pay(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("本次支付订单的提交信息 : {}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = ordersService.pay(ordersPaymentDTO);
        log.info("本次支付订单的响应信息 : {}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * 历史订单查询
     * @param ordersPageQueryDTO 查询参数(页码+页数+状态)
     * @return 全局通用返回信息Bean(总条数+OrderVO的List集合)
     */
    @ApiOperation("C端-用户查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> selectHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = ordersService.selectHistoryOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详情
     * @param orderId 订单Id
     * @return 全局通用返回信息Bean(订单基本信息+订单详细信息)
     */
    @ApiOperation("C端-查询订单详情")
    @GetMapping("/orderDetail/{orderId}")
    public Result<OrderVO> selectOrderDetail(@PathVariable Long orderId){
        OrderVO orderVO = ordersService.selectOrderDetails(orderId);
        return Result.success(orderVO);
    }

    /**
     * 取消订单
     * @param orderId 订单Id
     * @return 全局通用返回信息
     */
    @ApiOperation("C端-取消订单")
    @PutMapping("/cancel/{orderId}")
    public Result cancelOrder(@PathVariable Long orderId){
        ordersService.cancelOrder(orderId);
        return Result.success();
    }

    /**
     * 再来一单
     * @param orderId 订单Id
     * @return 全局通用返回信息
     */
    @ApiOperation("C端-再来一单")
    @PostMapping("/repetition/{orderId}")
    public Result repetitionOrder(@PathVariable Long orderId){
        ordersService.repetitionOrder(orderId);
        return Result.success();
    }

    /**
     * 用户催单
     * @param orderId 订单Id
     * @return 全局通用返回信息
     */
    @ApiOperation("C端-用户催单")
    @GetMapping("/reminder/{orderId}")
    public Result reminderOrder(@PathVariable Long orderId){
        log.info("本次用户催促的订单Id是：{}",orderId);
        ordersService.reminderOrder(orderId);
        return Result.success();
    }

}
